package com.zy.aop;

import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Aspect
public class Audience {

    @Pointcut("execution(* com.zy.aop.Performance.perform(..))")
    public void performance() {

    }

    // 表演之前
    @Before("performance()")
    public void silenceCellPhones() {
        System.out.println("手机静音");
    }

    // 表演前后
/*    @Around("performance()")
    public void around(ProceedingJoinPoint joinPoint) {
        try {
            System.out.println("手机静音");
            System.out.println("观众就坐");
            joinPoint.proceed();
            System.out.println("观众鼓掌");
        } catch (Throwable throwable) {
            System.out.println("观众退款");
        }
    }*/

    @Before("performance()")
    public void takeSeats() {
        System.out.println("观众就坐");
    }

    @AfterReturning("performance()")
    public void applause() {
        System.out.println("观众鼓掌");
    }

    /**
     * 方法返回或者抛出异常后调用
     */
    @After("performance()")
    public void after() {
        System.out.println("演出结束");
    }

    @AfterThrowing("performance()")
    public void demandRefund() {
        System.out.println("观众退款");
    }
}

